package Java_IO;

import java.io.File;

/**
 * @author shy_black
 * @date 2019/3/19 22:43
 * @Description:
 */

class Search implements Runnable {
    private File file;
    public Search(File file){
        this.file = file;
    }
    @Override
    public void run() {
        long start = System.currentTimeMillis();
        listAllFiles(file);
        long end = System.currentTimeMillis();
        System.out.println("遍历"+file+"盘共用时=="+(end-start)+"ms");
    }
    public void listAllFiles(File file) {
        if(file.isFile())
            System.out.println(file);
        else {
            if(file.exists() && file.isDirectory()) {
                File[] files = file.listFiles();
                if(files != null)
                    for(File file2 : files) {
                        listAllFiles(file2);
                    }
            }
        }
    }
}


public class 遍历文件test {
    public static void main(String[] args) {
        File file1 = new File("C:\\Users\\shy_black\\Desktop");
        File file2 = new File("D:\\test");
        Search search1 = new Search(file1);
        Search search2 = new Search(file2);
        Thread t1 = new Thread(search1);
        Thread t2 = new Thread(search2);
        t1.start();
        t2.start();
    }
}
